import express from 'express';
import cors from 'cors';
import path from 'path';

import router from './router';

const app = express();
const PORT = process.env.PORT||3000;

const corsOptions = {
  origin: `http://localhost:${PORT}`,
  // origin: 'http://example.com',
  // optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
}
app.use(cors(corsOptions))

// 设置静态文件夹
app.use('/public', express.static(path.join(__dirname, '../../dist')));

// 路由
router(app);
// 监听
app.listen(PORT, () => console.log(`Example app listening on port ${PORT}!`))
